DATS 6103 - Individual Project 1 - Arathi Nair

Analysis - Military Expenditure - (2010-2019)

• China
• Russia
• Germany
• UK
• France
• Italy
• Iran
• Saudi Arabia
• Israel
• South Korea
Data Sources :
• Military Expenditure Data - Stockholm International Peace Research Institute (SIPRI)
• Gross Domestic Product (GDP) Data - The World Bank (WBG)

Importing Packages

In [1]:
# Data cleaning and data analysis
import pandas as pd

# Data visualization
import plotly as py
import plotly.graph_objects as go
import plotly.express as px 

Importing Files

In [2]:
# Reading military spends data
mil_data= pd.read_excel("SIPRI-Milex-data-1949-2019.xlsx", 
                        sheet_name = "Current USD", 
                        skiprows = 5, index_col = "Country")
In [3]:
# Reading GDP data of countries
gdp_data = pd.read_csv("GDP2.csv", index_col = 1)
In [4]:
# Reading military share of GDP data
share_data = pd.read_excel("SIPRI-Milex-data-1949-2019.xlsx", 
                               sheet_name = "Share of GDP", 
                               skiprows = 5,index_col = "Country" )
In [5]:
# Reading military per capita data
milcap_data = pd.read_excel("SIPRI-Milex-data-1949-2019.xlsx", 
                        sheet_name = "Per capita", 
                        skiprows = 6,index_col = "Country")
In [6]:
# Reading GDP per capita data
gdpcap_data = pd.read_csv("GDPpercap.csv", index_col = 1)
In [7]:
# Reading Govt. spend for military data
govt_data = pd.read_excel("SIPRI-Milex-data-1949-2019.xlsx", 
                           sheet_name = "Share of Govt. spending", 
                           skiprows = 7,index_col = "Country")
In [8]:
# Check imported files

#mil_data.head()
#gdp_data.head()
#share_date.head()
#milcap_data.head()
#gdpcap_data.head()
#govt_data.head()

Filtering Data For Countries (2010 - 2019)

In [9]:
# Filtering military data by countries and years
mil_temp = mil_data.loc[["China", "UK", "Germany", "Russia", "France", "Italy", "Iran", 
                         "Saudi Arabia", "Israel","Korea, South"],
                        [2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019]]

# Renaming the columns
mil_temp.columns = ["Mil_2010", "Mil_2011","Mil_2012", "Mil_2013", "Mil_2014", "Mil_2015", 
                    "Mil_2016", "Mil_2017","Mil_2018","Mil_2019"]

# Converting military spends from millions to billions
mil = round(mil_temp.astype(float)/1000,2)
mil
Out[9]:
Mil_2010 Mil_2011 Mil_2012 Mil_2013 Mil_2014 Mil_2015 Mil_2016 Mil_2017 Mil_2018 Mil_2019
Country
China 115.71 137.97 157.39 179.88 200.77 214.47 216.40 228.47 253.49 261.08
UK 58.08 60.27 58.50 56.86 59.18 53.86 48.12 46.43 49.89 48.65
Germany 44.85 46.77 44.47 44.87 44.22 37.02 39.72 42.37 46.51 49.28
Russia 58.72 70.24 81.47 88.35 84.70 66.42 69.25 66.53 61.39 65.10
France 52.04 54.12 50.22 52.00 53.13 45.65 47.37 49.20 51.41 50.12
Italy 32.02 33.83 29.78 29.96 27.70 22.18 25.03 26.45 27.81 26.79
Iran 13.56 14.28 16.49 12.00 9.90 10.59 12.26 13.93 11.23 12.62
Saudi Arabia 45.24 48.53 56.50 67.02 80.76 87.19 63.67 70.40 74.40 61.87
Israel 13.88 15.16 14.60 16.32 17.81 16.52 17.49 19.43 19.76 20.46
Korea, South 28.18 30.99 31.95 34.31 37.55 36.57 36.89 39.17 43.07 43.89
In [10]:
# Filtering GDP data by countries and years
gdp_temp = gdp_data.loc[["CHN", "GBR", "DEU", "RUS", "FRA", "ITA", "IRN", "SAU", "ISR", "KOR"],
                        ["2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019"]]

# Adding country name column and setting it as the index
gdp_temp.insert(0,"Country",["China", "UK", "Germany", "Russia", "France", "Italy", "Iran", 
                             "Saudi Arabia", "Israel", "Korea, South"],False)

gdp_temp2 = gdp_temp.reset_index(drop = True).set_index("Country")

# Renaming columns
gdp_temp2.columns = ["GDP_2010","GDP_2011","GDP_2012", "GDP_2013", "GDP_2014", "GDP_2015", 
                     "GDP_2016", "GDP_2017","GDP_2018","GDP_2019"]

# Converting gdp spends from billions to trillions          
gdp= round(gdp_temp2/1000000000000,2)
gdp
Out[10]:
GDP_2010 GDP_2011 GDP_2012 GDP_2013 GDP_2014 GDP_2015 GDP_2016 GDP_2017 GDP_2018 GDP_2019
Country
China 6.09 7.55 8.53 9.57 10.48 11.06 11.23 12.31 13.89 14.34
UK 2.48 2.66 2.70 2.79 3.06 2.93 2.69 2.67 2.86 2.83
Germany 3.40 3.74 3.53 3.73 3.88 3.36 3.47 3.67 3.95 3.85
Russia 1.52 2.05 2.21 2.29 2.06 1.36 1.28 1.57 1.67 1.70
France 2.64 2.86 2.68 2.81 2.85 2.44 2.47 2.60 2.79 2.72
Italy 2.13 2.29 2.09 2.14 2.16 1.84 1.88 1.96 2.09 2.00
Iran 0.49 0.58 0.60 0.46 0.43 0.38 0.42 0.45 0.45 4.58
Saudi Arabia 0.53 0.67 0.74 0.75 0.76 0.65 0.64 0.69 0.79 0.79
Israel 0.23 0.26 0.26 0.29 0.31 0.30 0.32 0.35 0.37 0.40
Korea, South 1.14 1.25 1.28 1.37 1.48 1.47 1.50 1.62 1.72 1.64
In [11]:
# Filtering GDP share data by countries and years
share_temp = share_data.loc[["China", "UK", "Germany", "Russia", "France", "Italy", "Iran", 
                             "Saudi Arabia", "Israel", "Korea, South"],
                            [2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019]]

# Renaming columns
share_temp.columns = ["Share_2010", "Share_2011","Share_2012", "Share_2013", "Share_2014", 
                      "Share_2015", "Share_2016", "Share_2017", "Share_2018","Share_2019"]

# Converting shares into percentages
share = round(share_temp.astype(float)*100,2)

share
Out[11]:
Share_2010 Share_2011 Share_2012 Share_2013 Share_2014 Share_2015 Share_2016 Share_2017 Share_2018 Share_2019
Country
China 1.91 1.83 1.84 1.87 1.91 1.91 1.93 1.90 1.90 1.89
UK 2.37 2.29 2.19 2.07 1.95 1.86 1.81 1.77 1.77 1.74
Germany 1.32 1.25 1.26 1.20 1.14 1.10 1.15 1.16 1.18 1.28
Russia 3.58 3.42 3.69 3.85 4.10 4.86 5.45 4.23 3.72 3.88
France 1.97 1.89 1.87 1.85 1.86 1.87 1.92 1.91 1.85 1.86
Italy 1.51 1.49 1.44 1.41 1.29 1.21 1.34 1.36 1.34 1.35
Iran 2.91 2.38 2.76 2.24 2.28 2.76 2.97 3.11 2.46 2.31
Saudi Arabia 8.57 7.23 7.68 8.98 10.68 13.33 9.87 10.22 9.51 7.98
Israel 5.94 5.79 5.67 5.57 5.75 5.50 5.48 5.53 5.34 5.26
Korea, South 2.46 2.47 2.50 2.50 2.53 2.49 2.46 2.42 2.50 2.67
In [12]:
# Filtering military per capita data by countries and years
milcap_temp = milcap_data.loc[["China", "UK", "Germany", "Russia", "France", "Italy", "Iran", 
                               "Saudi Arabia", "Israel", "Korea, South"],
                              [2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019]]
# Renaming columns
milcap_temp.columns = ["Milcap_2010", "Milcap_2011","Milcap_2012", "Milcap_2013", "Milcap_2014", 
                       "Milcap_2015", "Milcap_2016", "Milcap_2017", "Milcap_2018","Milcap_2019"]
milcap = round(milcap_temp.astype(float),2)
milcap
Out[12]:
Milcap_2010 Milcap_2011 Milcap_2012 Milcap_2013 Milcap_2014 Milcap_2015 Milcap_2016 Milcap_2017 Milcap_2018 Milcap_2019
Country
China 84.53 100.23 113.70 129.24 143.46 152.45 153.04 160.78 177.56 182.09
UK 915.27 941.40 906.55 875.01 904.62 817.83 725.80 695.86 743.09 720.42
Germany 554.93 578.38 549.20 552.71 542.86 452.64 483.31 512.54 559.54 590.02
Russia 409.26 488.77 565.78 612.18 585.47 458.10 476.65 457.14 421.23 446.30
France 827.68 856.04 790.01 813.88 827.73 708.23 732.52 758.69 791.04 769.52
Italy 539.75 567.70 497.35 497.91 458.55 366.15 412.66 435.90 458.66 442.45
Iran 183.85 191.30 218.35 156.86 127.81 134.90 154.14 172.69 137.30 152.24
Saudi Arabia 1649.97 1716.84 1937.85 2230.13 2612.27 2748.81 1962.58 2126.81 2207.53 1805.35
Israel 1888.70 2025.25 1917.37 2110.56 2267.58 2070.16 2156.64 2357.41 2357.47 2402.16
Korea, South 568.67 622.50 638.26 681.51 742.02 719.57 723.48 766.60 841.68 856.82
In [13]:
# Filtering GDP per capita data by countries and years
gdpcap_temp = gdpcap_data.loc[["CHN", "GBR", "DEU", "RUS", "FRA", "ITA", "IRN", "SAU", "ISR", "KOR"],
                              ["2010", "2011", "2012", "2013", "2014", "2015", "2016", "2017", "2018", "2019"]]

# Adding country name column and setting it as the index
gdpcap_temp.insert(0,"Country",["China", "UK", "Germany", "Russia", "France", "Italy", "Iran", 
                                "Saudi Arabia", "Israel", "Korea, South"],False)
gdpcap_temp2 = gdpcap_temp.reset_index(drop = True).set_index("Country")

# Renaming columns
gdpcap_temp2.columns = ["GDPcap_2010","GDPcap_2011","GDPcap_2012", "GDPcap_2013", "GDPcap_2014", 
                        "GDPcap_2015", "GDPcap_2016", "GDPcap_2017","GDPcap_2018","GDPcap_2019"]

gdpcap= round(gdpcap_temp2,2)
gdpcap
Out[13]:
GDPcap_2010 GDPcap_2011 GDPcap_2012 GDPcap_2013 GDPcap_2014 GDPcap_2015 GDPcap_2016 GDPcap_2017 GDPcap_2018 GDPcap_2019
Country
China 4550.45 5618.13 6316.92 7050.65 7678.60 8066.94 8147.94 8879.44 9976.68 10261.68
UK 39435.84 42038.57 42462.77 43444.53 47425.61 44974.83 41064.13 40361.42 43043.23 42300.27
Germany 41531.93 46644.78 43858.36 46285.76 47959.99 41139.54 42098.92 44349.59 47639.00 46258.88
Russia 10675.00 14311.08 15420.87 15974.64 14095.65 9313.01 8704.90 10720.33 11370.81 11585.00
France 40638.33 43790.73 40874.70 42592.93 43011.26 36638.18 37037.37 38812.16 41631.09 40493.93
Italy 36000.52 38599.06 35053.53 35549.97 35518.42 30230.23 30939.71 32406.72 34520.09 33189.57
Iran 6599.66 7781.41 7927.85 6018.32 5585.53 4904.33 5253.42 5520.31 5416.53 5506.23
Saudi Arabia 19262.55 23745.80 25243.36 24844.74 24463.90 20627.93 19879.30 20803.74 23338.96 23139.80
Israel 30693.59 33669.25 32511.24 36309.47 37678.89 35776.80 37321.62 40541.86 41719.73 43641.40
Korea, South 23087.23 25096.26 25466.76 27182.73 29249.58 28732.23 29288.87 31616.84 33340.27 31761.98
In [14]:
# Filtering govt. spends data by countries and years
gov_temp = govt_data.loc[["China", "UK", "Germany", "Russia", "France", "Italy", "Iran", 
                          "Saudi Arabia", "Israel","Korea, South"],
                         [2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019]]

# Renaming columns
gov_temp.columns = ["Gov_2010", "Gov_2011","Gov_2012", "Gov_2013", "Gov_2014", 
                    "Gov_2015", "Gov_2016", "Gov_2017", "Gov_2018","Gov_2019"]

# Converting spends into percentages
gov = round(gov_temp.astype(float)*100,2)
gov
Out[14]:
Gov_2010 Gov_2011 Gov_2012 Gov_2013 Gov_2014 Gov_2015 Gov_2016 Gov_2017 Gov_2018 Gov_2019
Country
China 7.64 6.79 6.55 6.54 6.58 6.10 6.04 5.89 5.56 5.40
UK 5.32 5.29 5.05 4.98 4.81 4.69 4.66 4.60 4.61 4.54
Germany 2.74 2.76 2.81 2.67 2.57 2.50 2.59 2.62 2.64 2.83
Russia 10.12 10.32 10.84 11.12 11.77 13.81 14.83 12.13 11.36 11.37
France 3.46 3.36 3.28 3.23 3.26 3.30 3.39 3.39 3.30 3.34
Italy 3.02 3.01 2.83 2.75 2.53 2.41 2.73 2.79 2.76 2.77
Iran 15.16 13.01 19.32 15.61 14.80 15.43 15.21 16.05 13.47 13.34
Saudi Arabia 25.95 22.01 23.10 25.27 26.55 32.65 25.52 30.70 25.86 20.34
Israel 14.69 14.58 14.05 13.83 14.76 14.59 14.47 14.26 13.53 13.25
Korea, South 13.22 12.97 12.71 12.57 12.80 12.64 12.62 12.33 12.25 12.08
In [15]:
# Creating a master dataframe

df = pd.concat([mil,gdp,milcap,gdpcap,share,gov], axis = 1)
df
Out[15]:
Mil_2010 Mil_2011 Mil_2012 Mil_2013 Mil_2014 Mil_2015 Mil_2016 Mil_2017 Mil_2018 Mil_2019 ... Gov_2010 Gov_2011 Gov_2012 Gov_2013 Gov_2014 Gov_2015 Gov_2016 Gov_2017 Gov_2018 Gov_2019
Country
China 115.71 137.97 157.39 179.88 200.77 214.47 216.40 228.47 253.49 261.08 ... 7.64 6.79 6.55 6.54 6.58 6.10 6.04 5.89 5.56 5.40
UK 58.08 60.27 58.50 56.86 59.18 53.86 48.12 46.43 49.89 48.65 ... 5.32 5.29 5.05 4.98 4.81 4.69 4.66 4.60 4.61 4.54
Germany 44.85 46.77 44.47 44.87 44.22 37.02 39.72 42.37 46.51 49.28 ... 2.74 2.76 2.81 2.67 2.57 2.50 2.59 2.62 2.64 2.83
Russia 58.72 70.24 81.47 88.35 84.70 66.42 69.25 66.53 61.39 65.10 ... 10.12 10.32 10.84 11.12 11.77 13.81 14.83 12.13 11.36 11.37
France 52.04 54.12 50.22 52.00 53.13 45.65 47.37 49.20 51.41 50.12 ... 3.46 3.36 3.28 3.23 3.26 3.30 3.39 3.39 3.30 3.34
Italy 32.02 33.83 29.78 29.96 27.70 22.18 25.03 26.45 27.81 26.79 ... 3.02 3.01 2.83 2.75 2.53 2.41 2.73 2.79 2.76 2.77
Iran 13.56 14.28 16.49 12.00 9.90 10.59 12.26 13.93 11.23 12.62 ... 15.16 13.01 19.32 15.61 14.80 15.43 15.21 16.05 13.47 13.34
Saudi Arabia 45.24 48.53 56.50 67.02 80.76 87.19 63.67 70.40 74.40 61.87 ... 25.95 22.01 23.10 25.27 26.55 32.65 25.52 30.70 25.86 20.34
Israel 13.88 15.16 14.60 16.32 17.81 16.52 17.49 19.43 19.76 20.46 ... 14.69 14.58 14.05 13.83 14.76 14.59 14.47 14.26 13.53 13.25
Korea, South 28.18 30.99 31.95 34.31 37.55 36.57 36.89 39.17 43.07 43.89 ... 13.22 12.97 12.71 12.57 12.80 12.64 12.62 12.33 12.25 12.08

10 rows × 60 columns

In [16]:
# Checking for null values
null_columns = df.columns[df.isnull().any()]
df[null_columns].isnull().sum()

df.info()
<class 'pandas.core.frame.DataFrame'>
Index: 10 entries, China to Korea, South
Data columns (total 60 columns):
 #   Column       Non-Null Count  Dtype  
---  ------       --------------  -----  
 0   Mil_2010     10 non-null     float64
 1   Mil_2011     10 non-null     float64
 2   Mil_2012     10 non-null     float64
 3   Mil_2013     10 non-null     float64
 4   Mil_2014     10 non-null     float64
 5   Mil_2015     10 non-null     float64
 6   Mil_2016     10 non-null     float64
 7   Mil_2017     10 non-null     float64
 8   Mil_2018     10 non-null     float64
 9   Mil_2019     10 non-null     float64
 10  GDP_2010     10 non-null     float64
 11  GDP_2011     10 non-null     float64
 12  GDP_2012     10 non-null     float64
 13  GDP_2013     10 non-null     float64
 14  GDP_2014     10 non-null     float64
 15  GDP_2015     10 non-null     float64
 16  GDP_2016     10 non-null     float64
 17  GDP_2017     10 non-null     float64
 18  GDP_2018     10 non-null     float64
 19  GDP_2019     10 non-null     float64
 20  Milcap_2010  10 non-null     float64
 21  Milcap_2011  10 non-null     float64
 22  Milcap_2012  10 non-null     float64
 23  Milcap_2013  10 non-null     float64
 24  Milcap_2014  10 non-null     float64
 25  Milcap_2015  10 non-null     float64
 26  Milcap_2016  10 non-null     float64
 27  Milcap_2017  10 non-null     float64
 28  Milcap_2018  10 non-null     float64
 29  Milcap_2019  10 non-null     float64
 30  GDPcap_2010  10 non-null     float64
 31  GDPcap_2011  10 non-null     float64
 32  GDPcap_2012  10 non-null     float64
 33  GDPcap_2013  10 non-null     float64
 34  GDPcap_2014  10 non-null     float64
 35  GDPcap_2015  10 non-null     float64
 36  GDPcap_2016  10 non-null     float64
 37  GDPcap_2017  10 non-null     float64
 38  GDPcap_2018  10 non-null     float64
 39  GDPcap_2019  10 non-null     float64
 40  Share_2010   10 non-null     float64
 41  Share_2011   10 non-null     float64
 42  Share_2012   10 non-null     float64
 43  Share_2013   10 non-null     float64
 44  Share_2014   10 non-null     float64
 45  Share_2015   10 non-null     float64
 46  Share_2016   10 non-null     float64
 47  Share_2017   10 non-null     float64
 48  Share_2018   10 non-null     float64
 49  Share_2019   10 non-null     float64
 50  Gov_2010     10 non-null     float64
 51  Gov_2011     10 non-null     float64
 52  Gov_2012     10 non-null     float64
 53  Gov_2013     10 non-null     float64
 54  Gov_2014     10 non-null     float64
 55  Gov_2015     10 non-null     float64
 56  Gov_2016     10 non-null     float64
 57  Gov_2017     10 non-null     float64
 58  Gov_2018     10 non-null     float64
 59  Gov_2019     10 non-null     float64
dtypes: float64(60)
memory usage: 4.8+ KB

Military Expenditure Compared To GDP (in US$)

In [17]:
 def plot1(x):
        
    # Creating a loop to select military data from the master dataframe
    for i in range(10):
        yr = i + 2010
        gdp = "GDP_" + str(yr)
        mil = "Mil_" + str(yr)
        plot1 = df[[gdp,mil]].copy()
        
        # Plotting the data using scatter plot 
        fig = px.scatter(plot1, x = plot1[gdp], y = plot1[mil],size = plot1[gdp], 
                         color = plot1.index, size_max = 60)
        fig.update_traces(hovertemplate='GDP: %{x:$}T </br> </br> Mil: %{y:$}B') 
        fig.update_xaxes(title = "GDP ("+ str(yr) +")", range = [0,16],
                         tickprefix="$", ticksuffix="T")
        fig.update_yaxes(title = "Military Expenditure (" + str(yr) + ")", range = [0,300],
                         tickprefix="$", ticksuffix="B")
        fig.show()
    
        
plot1(plot1)

In this current list of countries, China accounts for the highest total GDP, as well as total military expenditure. This closely matches the country's economic growth and has also led to increasing annual military expenditure compared to its counterparts. Saudi Arabia has slowly increased its military expenditure over the years and has become the second highest spender in military along with Russia.

Military Expenditure Share Of GDP (in %)

In [18]:
# Using melt function to select gdp share data yearwise
temp_share= share.copy().reset_index()
temp_share.columns = ["Country",2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019]
plot2 = pd.melt(temp_share, id_vars = "Country")

# Plotting the data using bar chart
fig = px.bar(plot2, x = plot2["variable"], y = plot2["value"], 
             color = plot2["Country"], facet_col = plot2["Country"],
             title = "Military Expenditure Share Of GDP")
fig.update_layout(height=400, width = 1000, template = 'plotly_white', showlegend = False)
fig.update_traces(hovertemplate = "Mil:%{y:.2f}%") 
fig.update_xaxes(title = "2010 -'19", showticklabels = False)
fig.update_yaxes(title = "Military Share (%)",col = 1, ticksuffix="%")
fig.for_each_annotation(lambda a: a.update(text = a.text.split("=")[-1]))
fig.show()

However, the situation is quite different if we look at the military expenditure as a percentage share of the country's GDP. Saudi Arabia's military expenditure accounted the highest share of its GDP even with reduced military spends in the last few years. Similarly, Israel has comparatively spent a high share of GDP on its military expenses.

A Snapshot Of Overall Military Spending By Countries

In [19]:
# Using melt function to select military data yearwise
temp_mil = mil.copy().reset_index()
temp_mil.columns = ["Country",2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019]
plot3 = pd.melt(temp_mil,id_vars = ["Country"])

# Plotting data in an animated bar chart to show continuous yearwise transition
fig = px.bar(plot3, x = plot3["value"], y = plot3["Country"], color = plot3["Country"], 
             animation_frame = plot3["variable"],animation_group = plot3["Country"], range_x = [0,265])
fig.update_layout(height = 500, width = 900, template = 'plotly_white', showlegend = False)
fig.update_traces(hovertemplate = 'Mil:%{x:$}B') 
fig.update_xaxes(title = "Military Spend (in Billions)", range= [0,300],
                 tickprefix="$", ticksuffix="B")

fig.show()

Over the last decade, China has significantly increased its military expenditure making it the second largest military spender in the world. Meanwhile Saudi Arabia has incrementally increased its military expenditure and is now at par with Russia.

Military Per Capita Expenditure Compared To GDP Per Capita (in US$)

In [20]:
def plot4(x):
    
    # Creating a loop to select military and gdp per capita data from the master dataframe
    for i in range(10):
        yr = i + 2010
        gdpcap = "GDPcap_" + str(yr)
        milcap = "Milcap_" + str(yr)
        plot4 = df[[gdpcap,milcap]].copy()
        
        # Plotting the data using scatter plot 
        fig = px.scatter(plot4, x = plot4[gdpcap], y = plot4[milcap],
                         size = plot4[gdpcap], color = plot4.index, size_max = 60)
        fig.update_traces(hovertemplate = 'GDP Per Cap: %{x:$} </br> </br> Mil Per Cap: %{y:$}') 
        fig.update_xaxes(title = "GDP Per Capita ("+ str(yr) + ")", range = [0,50000],
                         tickprefix="$")
        fig.update_yaxes(title = "Military Per Capita (" + str(yr) + ")", range = [0,3000],
                         tickprefix="$", ticksuffix="k")
        fig.show()
    
        
plot4(plot4)

Located in high conflict region, countries like Israel and Saudi Arabia have the highest military per capita expenditure compared to their counterparts despite having a smaller population size.

Military Per Capita Expenditure Compared To GDP Per Capita (in %)

In [21]:
# Using melt function to military and gdp per capita data yearwise and adding a new percentage column
temp_milcap= milcap.copy().reset_index()
temp_gdpcap = gdpcap.copy().reset_index()
temp_milcap.columns = ["Country",2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019]
temp_gdpcap.columns = ["Country",2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019]

mcap_plot = pd.melt(temp_milcap, id_vars = "Country")
gcap_plot = pd.melt(temp_gdpcap, id_vars = "Country")
plot5  = pd.merge(mcap_plot,gcap_plot, on = mcap_plot.index, how = "left")
plot5["Per"] = round((plot5["value_x"]/plot5["value_y"])*100,2)

# Plotting the data using bar chart
fig = px.bar(plot5, x = plot5["variable_x"], y = plot5["Per"], 
             color = plot5["Country_x"], facet_col = plot5["Country_x"], 
             title = "Military Per Capita Expenditure To GDP Per Capita Expenditure")
fig.update_layout(height = 400, width = 1000, template = 'plotly_white', showlegend = False)
fig.update_traces(hovertemplate = "Mil Per Cap :%{y:.2f}%") 
fig.update_xaxes(title = "2010 -'19", showticklabels = False)
fig.update_yaxes(title = "Military Per Capita (%)",col = 1, ticksuffix="%")
fig.for_each_annotation(lambda a: a.update(text = a.text.split("=")[-1]))
fig.show()

The same pattern follows in terms of percentage spend on military per capita compared to GDP per capita. Saudi Arabia has the highest military per capita expense followed by Israel and Russia. For rest of the countries, military per capita expense compared to GDP per capita has comparatively been low and stable.

Government Spending On Military

In [22]:
# Using melt function to select govt. spends data yearwise
temp_gov = gov.copy().reset_index()
temp_gov.columns = ["Country",2010, 2011, 2012, 2013, 2014, 2015, 2016, 2017, 2018, 2019]
plot6 = pd.melt(temp_gov,id_vars=["Country"])


# Plotting the data using line chart
fig = px.line(plot6, x = plot6["variable"], y = plot6["value"], color = plot6["Country"],
              labels = {"x": "","y": "Military Share (%)","color": "Country"},
              title = "Military Share Of Govt. Spending", template = "ggplot2")
fig.update_traces(hovertemplate = 'Govt.Spend: %{y:.2f}%') 
fig.update_xaxes(title = "")
fig.update_yaxes(title = "Military Share(%)", ticksuffix="%")
fig.show()

Government expenditure on military is usually higher in countries with warlike situations and here we see that Saudi Arabia has allocated a higher share of government expenditure on its military. Iran also follows a similar trend and is at second position, while rest of the countries have a steady government expenditure on the military.

Fastest Growing Countries In Military Expenditure

In [23]:
# Calculating the average growth rate of military spending
tempmil = mil.copy()

def growth_rate(x):
    
    total = []
    for i in range(9):
        yr = i + 2011
        agr = ((tempmil["Mil_" + str(yr)] - tempmil["Mil_" + str(yr-1)])/tempmil["Mil_" + str(yr-1)])*100
        total.append(agr) 
    return(round(sum(total)/9,2))
    
growth_rate(tempmil)

# Plotting the annual growth rate using bar chart
plot7 = pd.DataFrame(growth_rate(tempmil))
fig = go.Figure(data = [go.Bar(name = 'Annual Growth Rate', x = plot7.index, y = plot7[0])])
fig.update_layout(yaxis_title = "Growth Rate (%)", title = "Average Annual Military Expenditure Growth Rate", 
                  template = "ggplot2")
fig.update_yaxes(title = "Military Share(%)", ticksuffix="%")
fig.update_traces(hovertemplate = '%{y:.2f}%', text = round(plot7[0],2) , textposition = "auto") 
fig.show()  

China's military expenditure growth rate is the highest due to its steady growing GDP and continuous investment in the military. Countries like Saudi Arabia, Israel and South Korea have also maintained similar growth rate. This increase in military expenditure by these countries is mainly because of the rising conflict with their neighboring regions. Whereas UK, France and Italy have reduced their military spends because of their slow GDP growth.

In [24]:
# Calculating year on year spending by each country

l=[]
def total(x):
    
    for i in range(10):
        yr = i+2010
        l.append(plot3.loc[plot3["variable"] == yr,"value"].sum())
total(plot3)

# Poltting the data using stacked bar chart
fig = px.bar(plot3, x = plot3["variable"], y = plot3["value"], color = plot3["Country"],
             color_discrete_sequence = px.colors.qualitative.Set2,
             title = "Total Military Expenditure Over The Decade", template = "plotly_white")
fig.update_traces(hovertemplate = 'Mil: %{y:$}B',width = .7) 
fig.update_xaxes(title = "")
fig.update_yaxes(title = "Military Spend (in Billion $)",tickprefix="$", ticksuffix="B")
fig.show()

Overall there has been a steady increase in military expenditure by these countries with a slight dip in 2015 & 2016 which could be due to slow economic growth during that period.

China has been the major contributor to this growth and has consistently been the highest spender among these nations. Saudi Arabia and Russia have also increased their military spends and are the second highest military spenders.

Regional Geopolitical situation which could possibly lead to a conflict has been the key driver for countries to invest more in this market.

Although the global military expenditure has been growing in the past few years, the unpredictable economic landscape caused due to Covid-19 pandemic could lead countries to reduce military budget and prioritize other pandemic responses & recovery projects in the coming years.